home *** CD-ROM | disk | FTP | other *** search
/ Delphi 2.0 - Programmer's Utilities Power Pack / Delphi 2.0 Programmer's Utilities Power Pack.iso / m_to_r / pprev101 / prntprev.int < prev    next >
Encoding:
Text File  |  1996-09-15  |  6.1 KB  |  149 lines

  1. unit PrntPrev;
  2.  
  3. interface
  4.  
  5. uses  WinProcs, SysUtils, Graphics, Classes, Printers, Forms,
  6.       Dialogs, DsgnIntf, WinTypes, StdCtrls, ExtCtrls, Buttons,
  7.       Controls;
  8.  
  9.    { TSpecialCanvas is passed in the PrintPageEvent.  It is used to print
  10.      transparently to either the screen or the printer.  All Output is sent
  11.      to the screen or printer, but all Input (i.e., TextWidth & TextHeight)
  12.      is received from the printer.  The units the user sees are always the
  13.      printer device units (usually pixels). This concept is very similar
  14.      to MFC's CDC object. }
  15.  
  16. type
  17.    TCanvasMode = (cmPreview, cmPrint);
  18.  
  19.    PreviewException = Class(Exception);
  20.  
  21.    TSpecialCanvas = class
  22.    public
  23.       { These are the "Special" variables & procedures }
  24.       DCanvas        : TCanvas;           { Display Canvas }
  25.  
  26.       constructor    Create;
  27.       destructor     Destroy;
  28.       procedure      PostPrinterSetup;                  { Call after Printer Setup to init variables }
  29.       procedure      SetDisplayMode(d: TCanvas);
  30.       procedure      SetPrintMode;
  31.  
  32.       procedure      Dump;
  33.  
  34.       property PageWidth: integer read FPageWidth;
  35.       property PageHeight: integer read FPageHeight;
  36.       property Xres: integer read FXres;
  37.       property Yres: integer read FYres;
  38.       property NoPrintLeft: integer read FNoPrintLeft;
  39.       property NoPrintTop: integer read FNoPrintTop;
  40.       property NoPrintRight: integer read FNoPrintRight;
  41.       property NoPrintBot: integer read FNoPrintBot;
  42.  
  43.       { Scaling functions }
  44.       function  XInch(i : single): integer;
  45.       function  YInch(i : single): integer;
  46.  
  47.       { These are the variables / procedures to mimic a TCanvas }
  48.       { Only ones missing are PenPos and Pixels }
  49.  
  50.       procedure Arc(X1, Y1, X2, Y2, X3, Y3, X4, Y4: integer);
  51.       procedure BrushCopy(const Dest: TRect; Bitmap: Graphics.TBitmap;
  52.         const Source: TRect; Color: TColor);
  53.       procedure Chord(X1, Y1, X2, Y2, X3, Y3, X4, Y4: integer);
  54.       procedure CopyRect(const Dest: TRect; Canvas: TCanvas;
  55.         const Source: TRect);
  56.       procedure Draw(X, Y: Integer; Graphic: TGraphic);
  57.       procedure DrawFocusRect(const Rect: TRect);
  58.       procedure Ellipse(X1, Y1, X2, Y2: integer);
  59.       procedure FillRect(const Rect: TRect);
  60.       procedure FloodFill(X, Y: integer; Color: TColor; FillStyle: TFillStyle);
  61.       procedure FrameRect(const Rect: TRect);
  62.       procedure MoveTo(X, Y: integer);
  63.       procedure LineTo(X, Y: integer);
  64.       procedure Pie(X1, Y1, X2, Y2, X3, Y3, X4, Y4: integer);
  65.       procedure Polygon(const Points: array of TPoint);
  66.       procedure Polyline(const Points: array of TPoint);
  67.       procedure Rectangle(X1, Y1, X2, Y2: integer);
  68.       procedure RoundRect(X1, Y1, X2, Y2, X3, Y3: integer);
  69.       procedure StretchDraw(const Rect: TRect; Graphic: TGraphic);
  70.  
  71.       procedure TextOut(X, Y: integer; const Text: string);
  72.       procedure TextRect(Rect: TRect; X, Y: integer; const Text: string);
  73.       function  TextWidth(const Text: string): integer;
  74.       function  TextHeight(const Text: string): integer;
  75.  
  76.       property  Font:TFont read FFont write SetFont;
  77.       property  Brush:TBrush read FBrush write SetBrush;
  78.       property  Pen:TPen read FPen write SetPen;
  79.       property  CopyMode:TCopyMode read FCopyMode write SetCopyMode;
  80.    end;
  81.  
  82.    { *** Print Preview Types *** }
  83.  
  84. type
  85.    { Generic Print/Print Preview Exception }
  86.    PrintException = Class(Exception);
  87.  
  88.    { TPageInfo is used to pass pagination information between the print
  89.      Preview component and the user's print events. }
  90.  
  91.    TPageInfo = class
  92.       CurPage  : integer;                 { The Current Page to Print }
  93.       LastPage : boolean;                 { True if its the Last Page }
  94.       Title    : string;                  { Print job Title           }
  95.    end;
  96.  
  97.  
  98.    { TBeginPrintEvent is called before any printing occurs.  It is passed a
  99.      NIL pointer, and it is up to the event to Create and return the TPageInfo
  100.      object.  Also note that the user may create a new object descended from
  101.      TPageInfo, and create and return that object instead. }
  102.  
  103.    TBeginPrintEvent = procedure(var Info: TPageInfo) of object;
  104.  
  105.    { TPrintPageEvent is called for each page to be printed or previewed.  The
  106.      Page to print is indicated by TPageInfo.CurPage.  The Event should
  107.      set TPageInfo.LastPage to TRUE if it is the last page to print, other-
  108.      wise FALSE.  Title is used to inform Print Manager of the name of the
  109.      document, and by the Print Status Window. }
  110.  
  111.    TPrintPageEvent  = procedure(var Info: TPageInfo; SCanvas: TSpecialCanvas) of object;
  112.  
  113.    { TEndPrintEvent is called after the print job is completed.  The event
  114.      should free the Info object and set its value to NIL. }
  115.  
  116.    TEndPrintEvent   = procedure(var Info: TPageInfo) of object;
  117.  
  118.  
  119.    { *** PRINT PREVIEW COMPONENT *** }
  120.  
  121. type
  122.  
  123.    { TPrintPreview - this is is!  The component the user drops on the form
  124.      to enable printing with Print Preview. }
  125.  
  126.    TPrintPreview = class(TComponent)
  127.    public
  128.       constructor    Create(AOwner: TComponent); override;
  129.       procedure      PrintPreview;
  130.       procedure      Print;
  131.       destructor     Destroy; override;
  132.    published
  133.       property OnBeginPrint: TBeginPrintEvent read FOnBeginPrint write FOnBeginPrint;
  134.       property OnPrintPage: TPrintPageEvent read FOnPrintPage write FOnPrintPage;
  135.       property OnEndPrint: TEndPrintEvent read FOnEndPrint write FOnEndPrint;
  136.       property ZoomOptions:TZoomOptions read FZoomOptions write SetZoomOptions;
  137.       property VisibleButtons:TVisibleButtons read FVisibleButtons write SetVisibleButtons;
  138.       property CurrentPage:integer read FCurrentPage write FCurrentPage default 1;
  139.       property GridColor:TColor read FGridColor write FGridColor default clSilver;
  140.       property GridWidth:integer read FGridWidth write FGridWidth default 2;
  141.       property Title:string read FTitle write FTitle;
  142.       property ShowGrid:boolean read FShowGrid write FShowGrid default False;
  143.       property About:TAbout read FAbout write SetAbout;
  144.    end;
  145.  
  146.    procedure Register;
  147.  
  148. implementation
  149.